package com.example.myweather.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHandler extends SQLiteOpenHelper{
	
	// All Static variables
	
	// Database Version
	public static final int DATABASE_VERSION = 1;

	// Database Name
	public static final String DATABASE_NAME = "Yawa";

	// Widgets Table Name
	public static final String TABLE_WIDGETS = "Widgets";
	

	// Widgets Table Columns Names
	public static final String KEY_WIDGETS_ID = "Widget_Id";
	public static final String KEY_WIDGETS_CITY_NAME = "City_Name";
	public static final String KEY_WIDGETS_COUNTRY_NAME = "Country_Name";
		
	
	public DataBaseHandler(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		// TODO Auto-generated constructor stub
	}
	
	// Creating Tables
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
			
		//Create a Widgets Table
		String CREATE_WIDGETS_TABLE = "CREATE TABLE " + TABLE_WIDGETS + "("
				+ KEY_WIDGETS_ID+ " INTEGER PRIMARY KEY, " + KEY_WIDGETS_COUNTRY_NAME + " TEXT,"
				+ KEY_WIDGETS_CITY_NAME + " TEXT " + ");";
		db.execSQL(CREATE_WIDGETS_TABLE);
	}
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
		// Drop older tables if existed
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_WIDGETS);
				
		// Create tables again
		onCreate(db);
	}
	
}
